// pages/news/newsSpecific/newsSpecific.js

const app = getApp();
var api = require('../../../api.js');
let WxParse = require('../../../wxParse/wxParse.js');
var mta = require('../../../mta_analysis.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var page = this ;
    console.log(options);
    page.setData({
      message_id:options.message_id
    });
    console.log(page.data.message_id);
    page.getDetail();

    wx.getNetworkType({
      success: function (res) {
        console.log(res)
        page.setData({
          networkType: res.networkType
        })
      }
    });

    mta.Page.init();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },

  //获取详情
  getDetail: function () {

    var that = this;

    var access_token = wx.getStorageSync('access_token');
    console.log(that.data.message_id);
    wx.request({
      url: api.message.detail,
      method: "get",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        access_token: access_token,
        message_id: that.data.message_id,
      },

      success: function (res) {
        console.log(res);
        

        if (res.data.code == 0) {
          console.log(res.data.data[0]);
          var article = res.data.data[0].note;
          that.setData({
            article:article
          })
          console.log(article);
          console.log(article.indexOf("<"))

          if (article.indexOf("<") != -1) {
            that.setData({
              judge: false
            })
            var temp = WxParse.wxParse('article', 'html', article, that, 5);
          } else {
            that.setData({
              judge: true
            })

          }
        }

      }
    });
  },
  back: function (e) {
    wx.navigateBack({
      delta: 1
    })
  },
})


